package com.zis.core;

import java.io.Serializable;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class ResponseEntity<T> implements Serializable {

	private static final long serialVersionUID = 4281230659824659225L;

	public static final int SUCCEED = 0;
	public static final int FAIL = 1;
	public static final int NULL = 2;
	public static final int TEST_ERROR = 3;
	private int code;
	private T responseData;

	public ResponseEntity(int code, T responseData) {
		this.code = code;
		this.responseData = responseData;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getResponseData() {
		return responseData;
	}

	public void setResponseData(T responseData) {
		this.responseData = responseData;
	}
	
	//测试webservice是否合法时，返回此提示
	public static final String createTestErrorJsonResponse(String msg){
		return JSONObject.fromObject(new ResponseEntity<String>(ResponseEntity.TEST_ERROR, msg)).toString();
	}
	
	public static final String createNULLJsonResponse(String msg) {
		return JSONObject.fromObject(new ResponseEntity<String>(ResponseEntity.NULL, msg)).toString();
	}

	public static final String createErrorJsonResponse(String msg) {
		return JSONObject.fromObject(new ResponseEntity<String>(ResponseEntity.FAIL, msg)).toString();
	}

	public static final String createNormalJsonResponse(String msg) {
		return JSONObject.fromObject(new ResponseEntity<String>(ResponseEntity.SUCCEED, msg)).toString();
	}

	public static final String createNormalJsonResponse(JSONObject jsonObject) {
		return JSONObject.fromObject(new ResponseEntity<JSONObject>(ResponseEntity.SUCCEED, jsonObject)).toString();
	}

	public static final String createNormalJsonResponse(JSONArray jsonArray) {
		return JSONObject.fromObject(new ResponseEntity<JSONArray>(ResponseEntity.SUCCEED, jsonArray)).toString();
	}
}
